<template>
	<view>
		<view class="list bot list1 list3">
			<view class="list2 bot1 bot2 bot3" @click="setAdministrator">
				<view>设置管理员</view>
				<image src="../../static/image/fanhui_21.png" class="fanhui"></image>
			</view>
			<view class="list2 bot1 bot2 bot3" @click="groupApply">
				<view>群申请</view>
				<image src="../../static/image/fanhui_21.png" class="fanhui"></image>
			</view>
			<view class="list2 bot1 bot2" @click="groupPersonNum">
				<view>群聊人数设置</view>
				<image src="../../static/image/fanhui_21.png" class="fanhui"></image>
			</view>
		</view>
		<view class="list list1 list2 bot bot1" @click="searchChat">
			<view>群内禁言</view>
			<switch class='blue' @change="SwitchA" :class="switchA?'checked':''" :checked="switchA?true:false"></switch>
		</view>
		<view class="gray grays">全员禁言启用后，只允许群主和管理员发言</view>
		<view class="list list1 list2 bot bot1" @click="searchChat">
			<view>群成员保护模式</view>
			<switch class='blue' @change="SwitchB" :class="switchB?'checked':''" :checked="switchB?true:false"></switch>
		</view>
		<view class="gray grays">开启后，群成员无法通过该群添加好友</view>
		<view class="list list1 list2 bot bot1" @click="searchChat">
			<view>是否开启群认证</view>
			<switch class='blue' @change="SwitchC" :class="switchC?'checked':''" :checked="switchC?true:false"></switch>
		</view>
		<view class="gray grays">开启后，需管理员同意才能加入群聊。同时将停用扫描二维码进群方式</view>
		<view class="list list1 list2 bot bot1" @click="searchChat">
			<view>群聊号</view>
			<view class="gray">{{group.groupnum}}</view>
		</view>
		<view class="list list1 list2 bot bot1" @click="editAdministrator">
			<view>群主管理转让</view>
			<image src="../../static/image/fanhui_21.png" class="fanhui"></image>
		</view>
		<view class="cu-modal" :class="modalName==1?'show':''">
			<view class="cu-dialog">
				<view class="quanxian">
					<image class="jinggao" src="../../static/image/jinghao_44.png"></image>
					您还不是VIP暂无权限
				</view>
				<view class="cu-bar bg-white">
					<view class="action margin-0 flex-sub  solid-left" @tap="hideModal">我知道了</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				switchA: false,
				switchB: true,
				switchC: true,
				group: [],
				group_id: '',
				stu: 2, //群主标识
				modalName: 2 //判断模态框是否显示
			}
		},
		onLoad(options){
			this.group_id = options.group_id;
			//this.initDat();
			// uni.onSocketMessage(function (res) {
			//   console.log('收到服务器内容：' + res.data);
			// });
		},
		onShow(){
			this.$msgchat.initwork();
			this.initDat();
			this.checkvip();
		},
		methods: {
			//初始化数据
			initDat(){
				var obj = {
					token: uni.getStorageSync('token'),
					group_id:this.group_id
				}
				this.$common.requests('/api/Group/groupmanage', obj).then(res => {
					console.log(res)
					if(res.data.code==1){
						this.group = res.data.data;
						this.switchA = res.data.data.is_say==1?false:true;
						this.switchB = res.data.data.is_protect==1?false:true;
						this.switchC = res.data.data.is_approve==1?false:true;
					}else{
						this.$api.msg(res.data.msg);
						return;
					}
					
				})
			},
			checkvip(){
				var obj = {
					token: uni.getStorageSync('token')
				}
				this.$common.requests('/api/Group/checkmyvip', obj).then(res => {
					console.log(res)
					if(res.data.code==1){
						this.stu = res.data.data.level?1:2;
					}else{
						this.$api.msg(res.data.msg);
						return;
					}
					
				})
			},
			SwitchA(e) {
				this.switchA = e.detail.value
				var obj = {
					token: uni.getStorageSync('token'),
					group_id:this.group_id,
					is_say:e.detail.value?2:1
				}
				this.$common.requests('/api/Group/setgroupmsg', obj).then(res => {
					// console.log(res)
					if(res.data.code==1){
						this.$api.msg(res.data.msg);
						return;
					}else{
						this.$api.msg(res.data.msg);
						return;
					}
					
				})
			},
			SwitchB(e) {
				this.switchB = e.detail.value
				var obj = {
					token: uni.getStorageSync('token'),
					group_id:this.group_id,
					is_protect:e.detail.value?2:1
				}
				this.$common.requests('/api/Group/setgroupprotect', obj).then(res => {
					// console.log(res)
					if(res.data.code==1){
						this.$api.msg(res.data.msg);
						return;
					}else{
						this.$api.msg(res.data.msg);
						return;
					}
					
				})
			},
			SwitchC(e) {
				this.switchC = e.detail.value
				var obj = {
					token: uni.getStorageSync('token'),
					group_id:this.group_id,
					is_approve:e.detail.value?2:1
				}
				this.$common.requests('/api/Group/setgroupapprove', obj).then(res => {
					// console.log(res)
					if(res.data.code==1){
						this.$api.msg(res.data.msg);
						return;
					}else{
						this.$api.msg(res.data.msg);
						return;
					}
					
				})
			},
			searchChat(){
				
			},
			//隐藏模态框
			hideModal(e) {
				this.modalName = 2
			},
			//设置管理员
			setAdministrator() {
				uni.navigateTo({
					url: '../setAdministrator/setAdministrator?group_id='+this.group_id
				})
			},
			groupApply(){
				uni.navigateTo({
					url: '../groupApply/groupApply?group_id='+this.group_id
				})
			},
			//群聊人数设置
			groupPersonNum(){
				if(this.stu == 2){
					this.modalName = 1
				}else{
					uni.navigateTo({
						url: '../groupPersonNum/groupPersonNum?group_id='+this.group_id
					})
				}
			},
			editAdministrator(){
				uni.navigateTo({
					url: '../editAdministrator/editAdministrator?group_id='+this.group_id
				})
			}
		}
	}
</script>

<style>
	page {
		width: 100vw;
		background: #F5F4F9;
		border-top: 1px solid #E8E8E8;
	}

	.list {
		background: #FFF;
		padding: 25upx 30upx;
	}

	.list1 {
		border-top: 1px solid #E8E8E8;
		border-bottom: 1px solid #E8E8E8;
	}

	.list2 {
		display: flex;
		justify-content: flex-start;
	}

	.bot {
		margin-top: 25upx;
		letter-spacing: 3upx;
	}

	.fanhui {
		width: 20upx;
		height: 30upx;
	}

	.bot1 {
		align-items: center;
		justify-content: space-between;
		padding: 35upx 30upx;
	}

	.bot2 {
		padding: 30upx 0;
	}

	.bot3 {
		border-bottom: 1px solid #E8E8E8;
	}

	.list3 {
		padding: 0 30upx;
	}

	.gray{
		font-size: 30upx;
		color: #787878;
	}
	.grays{
		padding: 10upx 30upx;
	}
	.quanxian {
		padding: 100upx 0;
		background: #FFF;
		border-bottom: 1px solid #E8E8E8;
		font-weight: 600;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.jinggao{
		width: 40upx;
		height: 40upx;
		margin: 0 20upx;
	}
	.solid-left {
		color: #4C68FF;
	}
</style>
